#include "Monster.h"

const Monster::MonsterColor Monster::colorBlue;
const Monster::MonsterColor Monster::colorViolet;
const Monster::MonsterColor Monster::colorWhite;

const Monster::MonsterType Monster::typeGolem;
const Monster::MonsterType Monster::typeLizard;
const Monster::MonsterType Monster::typeDrake;
const Monster::MonsterType Monster::typeBaron;

Monster::Monster(Monster::MonsterType monsterType, Monster::MonsterColor monsterColor,int respawnTime, QObject *parent) : QThread(parent){
    setMonsterType(monsterType);
    setMonsterColor(monsterColor);
    setRespawnTime(respawnTime);
    setAlive();
}



void Monster::kill(){
    emit signalStateChanged(false);
    this -> timeBeforeRespawn = this->respawnTime;
    this -> start();
}

void Monster::setAlive(){
    this -> isDead = false;
    this -> timeBeforeRespawn = 0;
    emit signalStateChanged(true);
}



int Monster::getRespawnTime(){
    return this->respawnTime;
}


void Monster::setMonsterType(Monster::MonsterType type){
    this ->monsterType = type;
}


void Monster::setMonsterColor(Monster::MonsterColor color){
    this -> monsterColor = color;
}


void Monster::setRespawnTime(int respawnTime){
    this->respawnTime = respawnTime;
}


Monster::MonsterType Monster::getMonsterType(){
    return this->monsterType;
}


Monster::MonsterColor Monster::getMonsterColor(){
    return this->monsterColor;
}



QString Monster::getMonsterType(Monster::MonsterType monsterType){
    QList<QString> types = QList<QString>() << "Golem" << "Lizard" << "Drake" << "Baron";
    return types[monsterType];
}


QString Monster::getMonsterColor(Monster::MonsterColor monsterColor){
    QList<QString> colors = QList<QString>() << "Blue" << "Violet" << "White";
    return colors[monsterColor];

}



QString Monster::getName(){
    return ((this -> getMonsterColor() != Monster::colorWhite) ? getMonsterColor(this->getMonsterColor()) : "") + " " + getMonsterType(this->getMonsterType()) ;
}


void Monster::run(){
    emit signalTimeBeforeRespawnChanged(this->respawnTime);
    while (this -> timeBeforeRespawn > 0){
        this -> timeBeforeRespawn -= 1000;
        this -> msleep(1000);
        emit signalTimeBeforeRespawnChanged(timeBeforeRespawn);
    }
    setAlive();
}
